# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution:
    def sumOfLeftLeaves(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
        # if not root:
        #     return 0
        # a = 0
        # m = []
        # m.append(root)
        # while m:
        #     v = m.pop()
        #     if v:
        #         if v.left:
        #             if not v.left.left and v.left.right:
        #                 a += v.left.val
        #         m.append(v.left)
        #         m.append(v.right)
        # return a
        if not root:
            return 0
        if root.left and not root.left.left and not root.left.right:
            return root.left.val + self.sumOfLeftLeaves(root.right)
        return self.sumOfLeftLeaves(root.left) + self.sumOfLeftLeaves(root.right)



m1 = TreeNode(1)
m1.left = TreeNode(2)
m1.right = TreeNode(3)
# m1.left.right =  TreeNode(5)
m1.right.left = TreeNode(6)
m1.right.right = TreeNode(2)
s = Solution()

t = s.sumOfLeftLeaves(m1)
print(t)
